package org.zjt.book.implicittest

import java.io.File

import scala.io.Source

/**
  * TODO: 只有同一个实例中可以定义不同隐式的转化器。
  */
object RichFile{
  implicit def file2RichFile(f:File)= new RichFile(f)
  implicit def str2RichFile(path:String)= new RichFile(new File(path))
  def read(richFile:RichFile) = Source.fromFile(richFile.file.getPath()).mkString
}


case class RichFile(file:File)

object Context{
  implicit def file2RichFile(f:File)= new RichFile(f)
}

object ImplictDemo {

  def main(args: Array[String]) {

    //import Context.file2RichFile
    implicit def file2RichFile(f:File) = new RichFile(f)
    println(RichFile.read("./test.txt"))


  }

}
